﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manager.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="B2B.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>ManageBuyingRequest</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
    <script type="text/javascript">
        function loadDanhMuc(maLinhVuc) {
            if (maLinhVuc != 0) {
                $.getJSON("/Home/DanhSachDanhMuc?id=" + maLinhVuc,
                 function (data) {
                     document.getElementById("checkCategory").innerText = "";
                     var s = '';
                     s += "<select id='MaDanhMuc' name='maDanhMuc'>";
                     for (i = 0 ; i < data.length; i++) {
                         s += "<option value='" + data[i].MaDanhMuc + "'>" + data[i].TenDanhMuc + "</option>";
                     }
                     s += "</select>";
                     $("#divDanhMuc").html(s);
                 });
            }
            else {
                document.getElementById("checkCategory").innerText = "Please select a item in category";
            }
        }

        function deleteProductPostbuyRequest(maspm, tr) {
            $.getJSON("/Manage/ProductDeletePostBuyRequest?id="+maspm,
                function (data) {
                    if (data == 1) {
                        // alert("Product deleted" + tr);
                        $("#postbuyrequest tr#tr" + tr).remove();
                    }
                    else
                        alert("You can't delete this product");
                });
        }

    </script>
    <%
        ArrayList list_SPM = (ArrayList)ViewData["list_SPM"];
        int i = 0;
    %>
     <h6> Management -> Product Post Buy</h6>
    <hr />
    <div>
        <table id="postbuyrequest" border="0">
             <tr style='background-color:#177f75; font-size:17px;color:#a6fdbf'>
                <th style="padding:5px; width:250px">Product Name</th>
                <th style="padding:5px; width:150px">Quality need</th>
                <th style="padding:5px; width:150px">Date</th>
                <th></th>
                <th></th>
            </tr>
            <%
                foreach(var spm in list_SPM)
                {
                    string tenSP = ((PostBuyRequest)spm).TenSanPham;
                    int soluongcan = ((PostBuyRequest)spm).SoLuongCanMua;
                    string ngaydang = ((PostBuyRequest)spm).NgayDang.ToShortDateString();
                    string tenDM = ((PostBuyRequest)spm).TenDanhMuc;
                    string chitiet = ((PostBuyRequest)spm).ChiTiet;
                    string hinhanh = ((PostBuyRequest)spm).HinhAnh;
                    int maSPM = ((PostBuyRequest)spm).MaSanPhamMua;
            %>

            <tr id="tr<%=i %>">
                <td style="padding:5px">
                       <a href="/Manage/ProductUpdatePostBuyRequest?id=<%=maSPM %>"><%=tenSP %></a>
                </td>
                <td style="padding:5px"><%=soluongcan %></td>
                <td style="padding:5px"><%=ngaydang %></td>
                <td style="padding:5px">
                    <a href="/Manage/ProductUpdatePostBuyRequest?id=<%=maSPM %>">Update</a>
                </td>
              <!--  <td style="padding:5px"><a class="btn" href="#" id="delete<%=i %>" onclick="deleteProductPostbuyRequest(<%=maSPM %>,'<%=i %>')">Delete</a></td>-->
                <td style="padding:5px"><input type="button" class="btn" id="delete<%=i %>" onclick="deleteProductPostbuyRequest(<%=maSPM %>,'<%=i %>')" value="Delete"/></td>
            </tr>           
            <%
                i++;
                }
            %>
         <!--   <tr><td colspan="5">1 2 3 4 5 6 7 8</td></tr>-->
            
        </table>
    </div>
    <div id="trigger-list">
                        <%
                            int tongTrangSP = int.Parse(ViewData["tongTrangPostbuy"].ToString());
                            for(int m = 0; m < tongTrangSP; m++)  {
                        %>
                            <a class="trigger error-trigger"  href="/Manage/ManageBuyingRequest/<%=m %>"><%=m+1 %></a>
                          
                       
                        <%} %>
                    </div>

</asp:Content>
